package com.mamahao.vmnetframework.framework.view

import android.app.Activity
import android.arch.lifecycle.Observer
import android.arch.lifecycle.ViewModel
import android.support.v4.app.FragmentActivity
import com.mamahao.vmnetframework.framework.event.ActionTodo
import com.mamahao.vmnetframework.framework.event.BaseActionEvent
import com.mamahao.vmnetframework.framework.viewmodel.BaseViewModel
import com.mamahao.vmnetframework.utils.ProgressBarUtils


fun FragmentActivity.initViewModel(viewModel: ViewModel, block: ((BaseActionEvent?) -> Boolean)? = null) : ViewModel{
    return viewModel.apply {
        if(this is BaseViewModel){
            mActionLiveData.observe(this@initViewModel, Observer<BaseActionEvent> {
                baseActionEvent: BaseActionEvent? ->
                ActionTodo.actionMessageTodo(this@initViewModel, baseActionEvent, block)
            })
        }
    }
}


fun Activity.showProgressBar() {
    ProgressBarUtils.showProgressBar(this)
}

fun Activity.hideProgressBar() {
    ProgressBarUtils.hideProgressBar(this)
}